package com.jiyici.model;

import java.util.ArrayList;

import jiyici.Constant.ModelColumn;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;

public class Item extends ClientBaseModel {

    private static final long serialVersionUID = 1525305121698177483L;

    public String itemName;

    public long categoryId;

    public String displayIndex;

    public int recordCount;

    public ArrayList<ItemParam> params = new ArrayList<ItemParam>();
    
    public void copyFrom(Item model) {
        super.copyFrom(model);
        itemName = model.itemName;
        categoryId = model.categoryId;
        displayIndex = model.displayIndex;
        recordCount = model.recordCount;
        params = model.params;
    }

    @Override
    public ContentValues toContentValues() {
        ContentValues values = super.toContentValues();
        values.put(ModelColumn.ITEM_COLUMN_NAME, itemName);
        values.put(ModelColumn.ITEM_COLUMN_CATEGORYID, categoryId);
        values.put(ModelColumn.ITEM_COLUMN_DISPLAY_INDEX, displayIndex);
        values.put(ModelColumn.ITEM_COLUMN_RECORD_COUNT, recordCount);
        return values;
    }

    @Override
    public void fromCursor(Cursor c) {
        super.fromCursor(c);
        itemName = c.getString(c.getColumnIndex(ModelColumn.ITEM_COLUMN_NAME));
        categoryId = c.getLong(c.getColumnIndex(ModelColumn.ITEM_COLUMN_CATEGORYID));
        displayIndex = c.getString(c.getColumnIndex(ModelColumn.ITEM_COLUMN_DISPLAY_INDEX));
        recordCount = c.getInt(c.getColumnIndex(ModelColumn.ITEM_COLUMN_RECORD_COUNT));
    }

    @Override
    public void fromJson(JSONObject json) throws JSONException {
        super.fromJson(json);
        itemName = json.getString(ModelColumn.ITEM_COLUMN_NAME);
        categoryId = json.getLong(ModelColumn.ITEM_COLUMN_CATEGORYID);
        displayIndex = json.getString(ModelColumn.ITEM_COLUMN_DISPLAY_INDEX);
        recordCount = json.getInt(ModelColumn.ITEM_COLUMN_RECORD_COUNT);
    }
    
    @Override
    public JSONObject toJson() throws JSONException {
        JSONObject json = super.toJson();
        json.put(ModelColumn.ITEM_COLUMN_NAME, itemName);
        json.put(ModelColumn.ITEM_COLUMN_CATEGORYID, categoryId);
        json.put(ModelColumn.ITEM_COLUMN_DISPLAY_INDEX, displayIndex);
        json.put(ModelColumn.ITEM_COLUMN_RECORD_COUNT, recordCount);
        return json;
    }

    @Override
    public String toString() {
        return "Item [id=" + id + ", userId=" + userId + ", lastmodified=" + lastmodified + ", deleted=" + deleted
                + ", dirty=" + dirty + ", itemName=" + itemName + ", categoryId=" + categoryId + ", displayIndex="
                + displayIndex + ", recordCount=" + recordCount + ", params=" + params + "]";
    }
}
